<template>
  <!-- 费用（条码申请项目） -->
  <div id="wLapplicationItem">
    <vxe-table ref="applicationItemTableList" v-loading="loading" border height="auto" :data="tableList" :footer-method="footerMethod" :merge-footer-items="[ { row: 0, col: 1, rowspan: 1, colspan: 5 } ]" :row-config="{ isCurrent: true, isHover: true }" :keyboard-config="{
            isArrow: true,
            isTab: true,
            isEdit: true
          }" footer-row-class-name="table-footer" show-footer resizable show-overflow>
      <vxe-column field="feeCode" title="编号" width="100"></vxe-column>
      <vxe-column field="adviceId" title="申请号码" align="left" min-width="160"></vxe-column>
      <vxe-column field="feeName" title="收费项目" align="left" min-width="160"></vxe-column>
      <vxe-column field="amount" title="数量" width="80" align="right"></vxe-column>
      <vxe-column field="price" title="单价" width="80" align="right"></vxe-column>
      <vxe-column field="costs" title="金额" width="80" align="right"></vxe-column>
    </vxe-table>
  </div>
</template>
<script setup lang="ts">
import { getCurrentInstance, reactive, ref } from 'vue';
import { Pane, Splitpanes } from 'splitpanes';
import { IsEmpty } from '@/utils/common';
import { VxeMessage, VxeNotifyType } from '@/utils/CommonMessage';
import 'vxe-table/lib/style.css'

let { proxy }: any = getCurrentInstance();

let reqNo = ref(''); //接收传过来的检验结果id
let tableList = reactive([]);
let specAdditionList = reactive([]);
let loading = ref(false);
let additionLoading = ref(false);
let applicationItemTableList = ref(null);
let modalShow = ref(false);
let isNotEdit = false;
let costTotal = ref(0.00);/**费用合计 */
let specAdditionForm = reactive({
  reqNo: '' //条码号)
}); //附加条码

defineExpose({
  getreqDetail,
  getCostTotal,
})

// 页面加载列表
function getreqDetail(repData: any) {
  if (IsEmpty(repData) || !repData) {
    tableList.length = 0;
    return;
  }
  reqNo.value = '';
  if (!IsEmpty(repData.reqNo)) {
    reqNo.value = repData.reqNo;
  }
  getDetail();
}

// 获取项目费用明细
function getDetail() {
  tableList.length = 0;
  loading.value = true;
  const url = '/api/reqdetail/findReqDetailByReqNo';
  proxy.$http
    .get(url, { params: { reqNo: reqNo.value } })
    .then(async (res: any) => {
      tableList.length = 0;
      Object.assign(tableList, res.data);
      loading.value = false;
    })
    .catch((err: any) => {
      VxeMessage(err, VxeNotifyType.error);
    });
}

// 表尾
function footerMethod({ columns, data }) {
  let count = 0;
  tableList.forEach(item => {
    count += item.price ? parseFloat(item.price) : 0;
  });
  costTotal.value = count;
  return [
    columns.map((column, _columnIndex) => {
      if (_columnIndex === 1) {
        return `金额合计: ${formatJe(count)}`;
      }
      return null;
    })
  ];
}
/**主界面获取费用合计 */
function getCostTotal() {
  return costTotal.value;
}
function formatJe(v) {
  if (Number.isNaN(v)) {
    return '';
  }
  return Number(v).toFixed(2);
}

function addSpecAddition() {
  modalShow.value = true;
}

// 设置行类名
function setRowClassName() {
  /*if (row.isAdditional) {
    return 'spec-addition';
  }*/
}

// 关闭弹框
function closeModal() {
  modalShow.value = false;
  specAdditionForm.reqNo = '';
}
// 获取是否静态的tag标记(绿/红)
function getIsStaticTagType(row: any) {
  if (row.isAddition === 0) {
    return 'success';
  } else {
    return 'danger';
  }
}


</script>
<style lang="scss" scoped>
#wLapplicationItem {
  height: 100%;
}
</style>